<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\WeeklyHoroscope;
use App\Models\Api\ZodiacSign;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class WeeklyHoroscopeController extends AdminController
{
    protected function grid()
    {
        return Grid::make(new WeeklyHoroscope(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('zodiac_sign_id')->sortable()->display(function ($inSign) {
                return $this->getZodiacSignNameAttribute($inSign);
            });
            $grid->column('title');
            $grid->column('introduction');
            $grid->column('content')->display(function ($content) {
            // 将内容截取为指定长度，并加上省略号
            return strlen($content) > 50 ? mb_substr($content, 0, 20) . '...' : $content;
        });
            $grid->column('created_at');
            $grid->column('updated_at');
        });
    }

    protected function form()
    {
        return Form::make(new WeeklyHoroscope(), function (Form $form) {
            $form->display('id');
            $form->select('zodiac_sign_id')->options($this->getZodiacSigns())->required();
            $form->text('title');
            $form->text('introduction');
            $form->textarea('content');
        });
    }
    
private function getZodiacSigns()
{
    return [
        1 => '白羊座',
        2 => '金牛座',
        3 => '双子座',
        4 => '巨蟹座',
        5 => '狮子座',
        6 => '处女座',
        7 => '天秤座',
        8 => '天蝎座',
        9 => '射手座',
        10 => '摩羯座',
        11 => '水瓶座',
        12 => '双鱼座'
    ];
}
}